import unittest
from time import sleep

import page
from base import log
from page.page_web_login import PageWebLogin
from page.page_web_order import PageWebOrder
from utils import GetDriver


class TestWebLogin(unittest.TestCase):
    def setUp(self) -> None:
        # 获取driver
        self.driver = GetDriver.get_web_driver()
        # 获取登录实例
        self.login = PageWebLogin(self.driver)
        # 获取发货实例
        self.order = PageWebOrder(self.driver)

    def tearDown(self) -> None:
        sleep(1)
        self.driver.quit()

    def test01_web_ok(self, username="admin", password="123456", code="8888"):
        try:
            self.login.page_web_login(username, password, code)
            nickname = self.login.page_web_get_nickname()
            print("登陆后的昵称为:", nickname)
            self.order.page_web_order()
            order_number = self.order.page_web_get_order_number()
            print("订单编号为:", order_number)
            log.info(f"--------------------------发货成功,发货的订单号为:{order_number}------------------------------")
            # self.assertEqual("admin", nickname)
            self.assertIn(order_number, page.order_on)
        except Exception as err:
            print("出现错误", err)
            log.error(err)
            # 截图
            self.order.base_screenshot()

